#ifndef _STRAWGUI_TEXTURE_RESOURCE_STRETCH_H_
#define _STRAWGUI_TEXTURE_RESOURCE_STRETCH_H_

#include "sSaveable.h"
#include "sConfig.h"
#include "sMath.h"

#ifdef _EDITOR
#include "sRTTIObject.h"
#endif

namespace sgui
{
namespace res
{    

enum EStretchMode {
	ESM_SCALE = 0,
	ESM_STRETCH
};

enum EStretchDivider
{
	ESD_FIRST = 0,
	ESD_SECOND,
	ESD_COUNT
};

struct sStretchMatrix
{
	math::sRectf m_data[3][3];
};

class sStretch: public sSaveable
#ifdef _EDITOR
, public rtti::sObject
#endif
{
private:

    static const f32 DEFAULT_DIVIDER;

	math::sPointsf		m_dividers[ESD_COUNT];
	EStretchMode		m_mode;

public:
    const math::sPointf& getDivider(EStretchDivider i) const { return m_dividers[i]; }
    math::sPointf& getDivider(EStretchDivider i) { return m_dividers[i]; }

	void getDataMatrix(sStretchMatrix& matrix, const math::sRectf& rect, const math::sPointf& texSize) const;
	void getTextureMatrix(sStretchMatrix& matrix, const math::sPointf& texSize) const;

	void setMode(const EStretchMode& value) { m_mode = value; }
    const EStretchMode& getMode() const { return m_mode; }

public:

	sStretch();

	void save(db::Record& file) const;
	void load(const db::Record& file);
	void clear();
#ifdef _EDITOR
	void exportRTTI(rtti::sInfoList& list);
#endif
};

};
};

#endif